﻿using System;
using System.Windows.Forms;
using ProgressViewed;
using WinProgressController;

namespace WinProgressView
{
    internal sealed class ProgressView : IProgressView
    {
        private ProgressController progController;
        private ProgressModelbase modelbase;

        public ProgressView (ProgressController controller, ProgressModelbase progModelbase)
        {
            this.progController = controller;
            this.modelbase = progModelbase;

            progController.Text = modelbase.Title;
        }

        public void Dispose ()
        {
            progController.Dispose();
            GC.SuppressFinalize (this);
        }

        public ProgressResult ShowModal ()
        {
            DialogResult result = progController.ShowDialog ();

            if (result == DialogResult.Cancel)
                return ProgressResult.Cancel;
            else
                return ProgressResult.TaskComplete;
        }

        public void Close ()
        {
            progController.DialogResult = DialogResult.OK;
        }

        public void SetText (string text)
        {
            progController.caption.Text = text;
        }

        public void SetMeter (int percent)
        {
            progController.progressBar.Value = percent;
        }
    }
}
